home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8032 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: gail.ripco.com!mambuhl
  2. From: mambuhl@ripco.com (Martin Ambuhl)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: gettimeofday() makes
  5. Date: 1 Mar 1996 06:00:14 GMT
  6. Organization: Ripco Communications, Inc.
  7. Message-ID: <4h63pe$osr@gail.ripco.com>
  8. NNTP-Posting-Host: golden.ripco.com
  9.  
  10. Carl@dudd.uniserve.com (Carl) in <208_9602292012@dudd.uniserve.com>
  11. wrote:
  12.  
  13. >What about if you use a function similar to the Borland  clock_t() which
  14. >returns the amount of clock ticks since program start.  Don't clock ticks
  15. >happen like 18 times per second on most systems?
  16.  
  17. Just to forestall any misperceptions arising from the above,
  18.  
  19. 1) clock_t is an aritmetic type capable of representing times.  It is
  20.     not a function.  It is defined by the ISO/ANSI standard and
  21.     Borland's use complies with the standard.
  22.  
  23. 2) The function which Carl has in mind is clock:
  24.     clock_t clock(void);
  25.    It should determine the the implementation's best approximation for
  26.    processor time used since the beginning of an implementation-defined
  27.    era related to the program invocation.  It is defined by the ISO/ANSI
  28.    standard and Borland's use complies with the standard. My copy of
  29.    Borland's documentation makes no reference to `clock ticks since
  30.    program start' or to the value of the macro CLOCKS_PER_SEC, which is
  31.    as it should be.
  32.  
  33. 3) The frequency of the clock tick is unrelated to the use of clock().
  34.    It returns a number of `clock_t' units, which are converted to
  35.    seconds by dividing that number by CLOCKS_PER_SEC.*  On my system, for
  36.    example, CLOCKS_PER_SEC is 543 times as large as the freqency of the
  37.    system clock.
  38.  
  39. 4) Because the era used for the value returned is only `related' to
  40.     program invocation, you will want (if the time from program start is
  41.     important), to save a returned value from clock() obtained at
  42.     program startup: `startup_clock = clock();'.  If you want the time
  43.     in clock_t units since program startup, clock()-startup_clock is a
  44.     good approximation.
  45.  
  46. * In some older implementations from Borland (and others),
  47. CLOCKS_PER_SEC may not be defined.  They use the older macro CLK_TCK.
  48. The easiest thing to do here, if the header is a text file, is to edit
  49. the header file.  Find the macro definition
  50.     #define CLK_TCK /* whatever */
  51. Copy it, substituting `CLOCKS_PER_SEC' for `CLK_TCK'.  Now you will no
  52. longer need worry about the ANSI macro name's being missing.
  53.                                                    
  54. --
  55. * Martin Ambuhl       net: mambuhl@ripco.com
  56. * Chicago, IL (USA)    
  57.